home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 2510.ZIP / TRSOURCE.EXE / REG.ASM < prev    next >
Assembly Source File  |  1990-10-22  |  7KB  |  216 lines

  1. ; REG.ASM
  2. ;
  3. ; by Ralph Davis
  4. ; modified by Rick Spence
  5. ;
  6. ; Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  7. ;
  8. ;     SYNTAX:  REG( <register name> )
  9. ;
  10. ; PARAMETERS:  <expC> = name of register in upper-case or lower-case
  11. ;
  12. ;              Valid registers are:
  13. ;
  14. ;              AX, BX, CX, DX, SP, BP, SI, DI, DS, ES, SS, CS, IP,
  15. ;              FF(Flags)
  16. ;
  17. ;    RETURNS:  Current contents of specified register as hexadecimal 
  18. ;              string.
  19. ;
  20.  
  21.          PUBLIC   REG
  22.  
  23.          INCLUDE  EXTENDA.MAC
  24.  
  25.          EXTRN    __TR_REG:FAR      ; C function which converts
  26.                                    ; register character string
  27.                                    ; to number
  28.                                    ; See EQUates below
  29.          EXTRN    __TR_HEXASM:FAR
  30.  
  31. ; Equates
  32.  
  33. ; These EQUates correspond to the codes set up in _tr_reg()
  34.  
  35. REG_AX   EQU      0
  36. REG_BX   EQU      1
  37. REG_CX   EQU      2
  38. REG_DX   EQU      3
  39. REG_SP   EQU      4
  40. REG_BP   EQU      5
  41. REG_SI   EQU      6
  42. REG_DI   EQU      7
  43. REG_DS   EQU      8
  44. REG_ES   EQU      9
  45. REG_SS   EQU     10
  46. REG_CS   EQU     11
  47. REG_IP   EQU     12
  48. REG_FF   EQU     13
  49.  
  50. DGROUP GROUP _DATA
  51. ;********************************************
  52. _DATA   SEGMENT WORD PUBLIC 'DATA'
  53.  
  54. NULLSTR   DB      0     ; For error return
  55.  
  56. _DATA   ENDS
  57. ;********************************************
  58.  
  59. ;********************************************
  60. REG_TEXT SEGMENT BYTE PUBLIC  'CODE'
  61.           ASSUME  CS:REG_TEXT,DS:_DATA
  62. ;--------------------------------------------
  63. REG       PROC    FAR
  64.           PUSH    BP            ; Caller's BP is now at [SP]
  65.           MOV     BP,SP         ; Caller's SP is BP+2
  66.           PUSH    AX            ; Save everybody
  67.           PUSH    BX
  68.           PUSH    CX
  69.           PUSH    DX
  70.           PUSH    SI
  71.           PUSH    DI
  72.           PUSH    DS
  73.           PUSH    ES
  74.           PUSH    SS
  75.           PUSHF                 ; Save flags in case they're wanted.
  76.  
  77. ; At this point, the stack looks like this:
  78. ;
  79. ;         SP+ 0:   Caller's flags
  80. ;           + 2:   Caller's SS
  81. ;           + 4:   Caller's ES
  82. ;           + 6:   Caller's DS
  83. ;           + 8:   Caller's DI
  84. ;           +10:   Caller's SI
  85. ;           +12:   Caller's DX
  86. ;           +14:   Caller's CX
  87. ;           +16:   Caller's BX
  88. ;           +18:   Caller's AX
  89.  
  90. ; In addition:
  91. ;
  92. ;         BP contains the caller's stack pointer minus 2.
  93. ;         
  94. ;          BP+0:    Caller's BP
  95. ;          BP+2:    Caller's IP
  96. ;          BP+4:    Caller's CS
  97. ;          BP+6:    Pointer to desired register
  98. ;          
  99.  
  100.            GET_CHAR 1             ; Get pointer to register string
  101.            PUSH     DX            ; and pass it to _tr_reg()
  102.            PUSH     AX
  103.            CALL     __TR_REG      ; Convert it to a number
  104.                                   ; Returns integer in AX
  105.            ADD      SP,4
  106.            PUSH     SS            ; Use DS and BX to address
  107.            POP      DS            ;   data saved on the stack
  108.            MOV      BX,SP         ; 
  109.            CMP      AX,REG_AX     ; AX desired?
  110.            JNE      REG1
  111.            MOV      AX,[BX+18]    ; Yes, pick it up
  112.            JMP      REG20         ; and get out
  113. REG1:
  114.            CMP      AX,REG_BX     ; BX desired?
  115.            JNE      REG2
  116.            MOV      AX,[BX+16]    ; Yes
  117.            JMP      REG20
  118. REG2:
  119.            CMP      AX,REG_CX     ; CX desired?
  120.            JNE      REG3
  121.            MOV      AX,[BX+14]    ; Yes
  122.            JMP      REG20
  123. REG3:
  124.            CMP      AX,REG_DX     ; DX desired?
  125.            JNE      REG4
  126.            MOV      AX,[BX+12]    ; Yes
  127.            JMP      REG20
  128. REG4:
  129.            CMP      AX,REG_SP     ; SP desired?
  130.            JNE      REG5
  131.            MOV      AX,BP         ; Yes
  132.            ADD      AX,2          ; Old SP = Current BP + 2
  133.            JMP      REG20
  134. REG5:
  135.            CMP      AX,REG_BP     ; BP desired?
  136.            JNE      REG6
  137.            MOV      AX,[BP]       ; Yes
  138.            JMP      REG20
  139. REG6:
  140.            CMP      AX,REG_SI     ; SI desired?
  141.            JNE      REG7
  142.            MOV      AX,[BX+10]    ; Yes
  143.            JMP      REG20
  144. REG7:
  145.            CMP      AX,REG_DI     ; DI desired?
  146.            JNE      REG8
  147.            MOV      AX,[BX+8]     ; Yes
  148.            JMP      REG20
  149. REG8:
  150.            CMP      AX,REG_DS     ; DS desired?
  151.            JNE      REG9
  152.            MOV      AX,[BX+6]     ; Yes
  153.            JMP      REG20
  154. REG9:
  155.            CMP      AX,REG_ES     ; ES desired?
  156.            JNE      REG10
  157.            MOV      AX,[BX+4]     ; Yes
  158.            JMP      REG20
  159. REG10:
  160.            CMP      AX,REG_SS     ; SS desired?
  161.            JNE      REG11
  162.            MOV      AX,[BX+2]     ; Yes
  163.            JMP      REG20
  164. REG11:
  165.            CMP      AX,REG_CS     ; CS desired?
  166.            JNE      REG12
  167.            MOV      AX,[BP+4]     ; Yes
  168.            JMP      REG20
  169. REG12:
  170.            CMP      AX,REG_IP     ; IP desired?
  171.            JNE      REG13
  172.            MOV      AX,[BP+2]     ; Yes
  173.            JMP      REG20
  174. REG13:
  175.            CMP      AX,REG_FF     ; Flags desired?
  176.            JNE      REG14
  177.            MOV      AX,[BX]       ; Yes
  178.            JMP      REG20
  179. REG14:
  180.            MOV      DX,_DATA           ; Return null string
  181.            MOV      AX,OFFSET NULLSTR   ; for invalid register
  182.            JMP      EXIT
  183. REG20:
  184.            ; At this point, AX contains return value
  185.            ; 
  186.            ; Call _TR_HEXASM to convert it to a hexadecimal string
  187.           
  188.            XOR      BX,BX           ; Push a word of zeroes
  189.            PUSH     BX              ; so _TR_HEXASM will know we only
  190.                                     ; want a 4-digit string
  191.            PUSH     AX
  192.            CALL     __TR_HEXASM     ; DX:AX now contains pointer
  193.                                     ; to return string
  194.            ADD      SP,4
  195. EXIT:
  196.            POPF                     ; Restore caller's flags and registers
  197.            POP      SS
  198.            POP      ES
  199.            POP      DS
  200.            POP      DI
  201.            POP      SI
  202.            ADD      SP,2
  203.            POP      CX
  204.            POP      BX
  205.            ADD      SP,2             ; Discard saved values
  206.                                      ; of DX and AX
  207.            POP      BP
  208.            RET_CHAR DX,AX            ; Return char * to caller
  209.            RET
  210. REG        ENDP
  211. ;-------------------------------------------
  212. REG_TEXT     ENDS
  213. ;*******************************************
  214.            END
  215.  
  216.